/**
 * FileName: answer_3
 * Author:   why
 * Date:     2019/3/12 17:47
 * Description: 一次hash
 */
package algorithm.leetcode.problem_1;

import java.util.HashMap;
import java.util.Map;

public class answer_3 {
    public static int[] twoSum(int[] nums, int target) {

        Map<Integer, Integer> mp = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int number = target - nums[i];
            if (mp.containsKey(number)) {
                return new int[]{mp.get(number), i};
            }
            //上面跟之前的差不多 只不过刚开始mp是空的 当mp匹配到一次 就说明找到了 如果没找到 就往mp中放
            mp.put(nums[i], i);
        }
        throw new IllegalArgumentException("no answer_2 sum solution");

    }
}
